package com.movie.ticket.sale.movieinterface.aheadcontroller;

import com.movie.ticket.sale.movieinterface.common.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author： Micsal
 * @create-time： 2020.12.03 20:00
 * @version： 1.0
 * @description： 短信管理，放在util包
 */
@Api(tags = "短信管理(MessageUtil)，属于ticket服务",description = "发送短信，校验短信")
@RequestMapping("/message")
@RestController
public class MessageUtil {

    @ApiOperation("发送短信")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tel",value = "电话号码",dataType="int",paramType = "query"),
            @ApiImplicitParam(name = "message",value = "短信的内容",dataType="string",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code=200,response = Result.class,message = "成功,返回Result.success"),
            @ApiResponse(code=426,response = Result.class,message = "失败，信息存result.message中")
    })
    @GetMapping("/send")
    public static Result sendMessage(String tel,String message){
        /**
         * 校验redis中是否有该手机号的key，有则取出，获取时间，1分钟之内则不重复发，超过1分钟，覆盖
         * 调用发短信的api
         * 将信息发送出
         */
        return null;
    }

    @ApiOperation("验证短信")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tel",value = "电话号码",dataType="int",paramType = "query"),
            @ApiImplicitParam(name = "code",value = "短信的内容",dataType="string",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code=200,response = Result.class,message = "校验成功，返回true"),
            @ApiResponse(code=426,response = Result.class,message = "校验失败，返回false")
    })
    @PostMapping("/check")
    public static Result checkMessage(String tel,String code){
        /**
         * key:手机号 value:"存入时间，验证码，有效时长(分钟)"
         * 校验key是否存在
         * 校验时间是否过期
         * 校验验证码是否正确
         */
        return null;
    }
}
